home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
GSRC208A.ZIP
/
GETALL.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-25
|
27KB
|
880 lines
#include "copyleft.h"
/*
GEPASI - a simulator of metabolic pathways and other dynamical systems
Copyright (C) 1989, 1992, 1993 Pedro Mendes
*/
/*************************************/
/* */
/* data input */
/* */
/* Zortech C/C++ 3.0 r4 */
/* MICROSOFT C 6.00 */
/* Visual C/C++ 1.0 */
/* QuickC/WIN 1.0 */
/* ULTRIX cc */
/* GNU gcc */
/* */
/* (include here compilers that */
/* compiled GEPASI successfully) */
/* */
/*************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef MSDOS
#include <io.h>
#endif
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <math.h>
#include "globals.h"
#include "globvar.h"
#include "datab.h"
#include "newton.h"
#include "strtbl.h"
#include "gauss.h"
#include "kinetics.h"
#include "pmu.h" /* several utilities */
#include "heapchk.h"
#if ( _MSC_VER >= 610 )
#define open _open
#define close _close
#define stat _stat
#define fstat _fstat
#define read _read
#define write _write
#define O_RDONLY _O_RDONLY
#endif
#ifdef _ZTC
#define MEM_DEBUG 1
#include "mem.h"
#else
#define mem_malloc malloc
#define mem_free free
#define mem_realloc realloc
#endif
/*
get the list of files to process
*/
void getlist( char *inpf )
{
int i;
FILE *chg;
if ( inpf )
{
if (!(chg=fopen(inpf,"r")))
{
printf(errormsg[6],inpf);
term_gepasi();
}
}
else
{
chg = stdin;
fprintf( stderr, "\n\n%s\n\n", gepasi );
fprintf( stderr, "input filenames one at a line, a dot followed by ENTER ends.\n\n");
}
for(i=0;i<MAX_FIL;i++) /* stop at MAX_FIL */
{
fgets( filename[i], PWIDTH, chg );
if ( ( filename[i][0] == '.' )
|| ( feof( chg ) )
) break; /* stop if EOF or . */
filename[i][strlen(filename[i])-1] = 0; /* put /0 at the end */
fixext( filename[i], '.', ".sim" );
}
nrunfiles = i;
if ( inpf ) fclose( chg );
return;
}
/*
read topology from file
*/
int BufToTop( char *Buff, char **endoftop )
{
int i,j;
int daux;
unsigned char uaux;
char *paux;
char saux[NAME_L];
/* reset the version number to zero */
ver_no = 0;
/* copy the first line */
paux = strchr( Buff, '\n' );
if( paux == NULL ) return IDS_ERR_BAD_TOPNAM;
/* take care of CR if one existed before LF */
if( *(paux-1)=='\r' ) *(paux-1) = '\0';
*paux = '\0';
if( strlen( Buff ) > 255 ) Buff[255] = '\0';
strcpy( topname, Buff );
Buff = paux+1;
/* is this line a version number ? */
sscanf( topname, "version %f", &ver_no );
if( ver_no != 0 )
{
/* YES! so let's read another line, with the title */
paux = strchr( Buff, '\n' );
if( paux == NULL ) return IDS_ERR_BAD_TOPNAM;
if( *(paux-1)=='\r' ) *(paux-1) = '\0';
*paux = '\0';
if( strlen( Buff ) > 255 ) Buff[255] = '\0';
strcpy( topname, Buff );
Buff = paux+1;
}
/* read nstep from the buffer */
if ( ( sscanf( Buff, " %d", &daux ) < 1) ||
( daux < 1 ) || ( daux > MAX_STEP ) )
return IDS_ERR_BAD_NSTEP;
nsteps = daux;
Buff = strchr( Buff, ' ' );
/* read totmet from the buffer */
if( (Buff == NULL ) || ( sscanf( ++Buff, " %d", &daux ) < 1) ||
( daux < 1 ) || ( daux > MAX_MET ) )
return IDS_ERR_BAD_TOTMET;
totmet = daux;
/* read stoiu from the buffer */
for(i=0;i<totmet;i++)
for(j=0;j<nsteps;j++)
{
if(j==0)
{
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
{
Buff++;
for( ;*Buff == ' '; Buff++);
}
}
else
{
Buff = strchr( Buff, ' ' );
if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
}
if ( (Buff == NULL) || (sscanf( Buff, "%d", &daux ) < 1) )
return IDS_ERR_BAD_STOI;
stoiu[i][j] = daux;
}
Buff = strchr( Buff, '\n' );
if( Buff == NULL ) return IDS_ERR_BAD_KINTYPE;
Buff++;
/* read kinetu, revers and metname from the buffer */
for( i=0; i<nsteps; i++ )
{
for( ;*Buff == ' '; Buff++);
if ( (Buff == NULL) || (sscanf( Buff, "%d", &daux ) < 1)
|| (daux < -1) )
return IDS_ERR_BAD_KINTYPE;
kinetu[i] = daux;
Buff = strchr( Buff, ' ' );
if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
if ( (Buff == NULL) || (sscanf( Buff, "%d", &daux ) < 1) )
return IDS_ERR_BAD_KINTYPE;
revers[i] = daux;
Buff = strchr( Buff, ' ' );
if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
paux = strchr( Buff, '\n' );
if( paux == NULL ) return IDS_ERR_BAD_KINTYPE;
/* take care of CR if one existed before LF */
if( *(paux-1)=='\r' ) *(paux-1) = '\0';
*paux = '\0';
if( strlen( Buff ) >= NAME_L ) Buff[NAME_L-1] = '\0';
strcpy( stepname[i], Buff );
Buff = paux+1;
}
*(--Buff) = '\n';
/* read rstr from the buffer */
for(i=0;i<nsteps;i++)
for(j=0;j<MAX_MOL;j++)
{
if(j==0)
{
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
{
Buff++;
for( ;*Buff == ' '; Buff++);
}
}
else
{
Buff = strchr( Buff, ' ' );
if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
}
if ( (Buff == NULL) || (sscanf( Buff,"%d", &daux ) < 1) )
return IDS_ERR_BAD_LOOP;
(*rstr)[i][j] = (signed char) daux;
}
/* read loop from the buffer */
for(i=0;i<nsteps;i++)
for(j=0;j<totmet;j++)
{
if(j==0)
{
Buff = strchr( Buff, '\n' );
if( Buff != NULL )
{
Buff++;
for( ;*Buff == ' '; Buff++);
}
}
else
{
Buff = strchr( Buff, ' ' );
if( Buff != NULL ) for( ;*Buff == ' '; Buff++);
}
if ( (Buff == NULL) || (sscanf( Buff,"%u", &uaux ) < 1)
|| (uaux < 0) )
return IDS_ERR_BAD_LOOP;
(*loop)[i][j] = uaux;
}
/* read metabolite status and names from the buffer */
for(i=0;i<totmet;i++)
{
Buff = strchr( Buff, '\n' );
if ( (Buff == NULL) || (sscanf( ++Buff, "%d %21s", &daux, saux ) < 2) )
return IDS_ERR_BAD_INTMET;
intmet[i] = daux;
strcpy( metname[i], saux );
}
/* point endofbuf to the end of the topology section */
if( endoftop != NULL )
*endoftop = Buff;
/* return and signal that function was successful */
return 0;
}
int BufToTree( char *Buff, char **endoftree )
{
int i;
char *paux;
int daux, daux1, daux2;
char caux[10];
float faux;
/* copy the title from the buffer */
paux = strchr( Buff, '\n' );
if( paux == NULL ) return IDS_ERR_LOAD;
/* take care of CR if one existed before LF */
if( *(paux-1)=='\r' ) *(paux-1) = '\0';
*paux = '\0';
if( strlen( Buff ) > 63 ) Buff[63] = '\0';
strcpy( tr.descr, Buff );
Buff = paux+1;
/* read nnode from the buffer */
if ( sscanf( Buff, "%d", &daux ) < 1 )
return IDS_ERR_LOAD;
tr.nnode = daux;
Buff = strchr( Buff, ' ' );
/* read nid from the buffer